/**
 *
 * @param date new Date()类型
 * @returns yyyt-MM-dd HH:mm
 */
export function dateFormat(date){
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以需要+1
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');

    const currentTime = new Date();

    if (currentTime.getFullYear() === year && String(currentTime.getMonth() + 1).padStart(2, '0') === month
        && String(currentTime.getDate()).padStart(2, '0') === day) {
        return `${hours}:${minutes}`;
    } else if (currentTime.getFullYear() === year) {
        return `${month}-${day} ${hours}:${minutes}`;
    } else {
        return `${year}-${month}-${day} ${hours}:${minutes}`;
    }
}

/**
 * 格式化时间
 * @param isoString 形如 2024-07-19T03:25:05.885+00:00
 * @returns {string}
 */
export function formatISODate(isoString) {
    // 创建一个 Date 对象
    const date = new Date(isoString);

    // 获取年份、月份、日期、小时、分钟、秒
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以需要+1
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');

    const currentTime = new Date();

    if (currentTime.getFullYear() === year && String(currentTime.getMonth() + 1).padStart(2, '0') === month
    && String(currentTime.getDate()).padStart(2, '0') === day) {
        return `${hours}:${minutes}`;
    } else if (currentTime.getFullYear() === year) {
        return `${month}-${day} ${hours}:${minutes}`;
    } else {
        return `${year}-${month}-${day} ${hours}:${minutes}`;
    }
}